package com.xscr.forum.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.xscr.forum.mapper.ForumReplyMapper;
import com.xscr.forum.mapper.ForumTopicMapper;
import com.xscr.forum.po.ForumReply;
import com.xscr.forum.po.ForumTopic;
import com.xscr.forum.service.ForumReplyService;
import com.xscr.forum.service.ForumTopicService;
import com.xscr.mybatis.utility.PageBean;

public class ForumTopicServiceImpl implements ForumTopicService {

	@Autowired
	private ForumTopicMapper forumTopicMapper;

	@Override
	public int saveForumTopic(ForumTopic forumTopic) throws Exception {
		return forumTopicMapper.insertSelective(forumTopic);
	}

	@Override
	public int saveListForumTopic(List<ForumTopic> forumTopic) throws Exception {
		return forumTopicMapper.insertListForumTopic(forumTopic);
	}

	@Override
	public int deleteForumTopicById(Integer id) throws Exception {
		ForumTopic forumTopic = new ForumTopic();
		forumTopic.setTopicId(id);
		forumTopic.setStatus(-1);
		
		return forumTopicMapper.updateByPrimaryKeySelective(forumTopic);
	}

	@Override
	public int updateForumTopic(ForumTopic forumTopic) throws Exception {
		return forumTopicMapper.updateByPrimaryKeySelective(forumTopic);
	}

	@Override
	public ForumTopic findForumTopicById(Integer id) throws Exception {
		return forumTopicMapper.selectByPrimaryKey(id);
	}

	@Override
	public PageBean<ForumTopic> findForumTopicByConditions(
			PageBean<ForumTopic> pageBean) throws Exception {
		List<ForumTopic> selectForumTopicListPage = forumTopicMapper.selectForumTopicListPage(pageBean);
		
		pageBean.setResult(selectForumTopicListPage);
		
		return pageBean;
	}

	@Override
	public List<ForumTopic> findForumTopicByConditions(ForumTopic forumTopic)
			throws Exception {
		PageBean<ForumTopic> pageBean = new PageBean<ForumTopic>();
		
		pageBean.setParameter(forumTopic);
			
		return forumTopicMapper.selectForumTopicListPage(pageBean);
	}
	
	@Override
	public List<ForumTopic> findForumTopicByCircleId(Integer circleId)
			throws Exception {
		
		ForumTopic forumTopic=new ForumTopic();
		forumTopic.setCircleId(circleId);
		PageBean<ForumTopic> pageBean = new PageBean<ForumTopic>();
		
		pageBean.setParameter(forumTopic);
			
		return forumTopicMapper.selectForumTopicListPage(pageBean);
	}
	

}
